<template>
	<div>
		<div style="font-size:18px;margin-bottom: 15px;">
			<a href="#" @click="prev" style="text-decoration:none;font-size: 14px;">
				<icon-svg name="jiantou" style="width: 1.2em;height: 1.2em;position: relative;top: 0.3em;"></icon-svg>
				返回
			</a>
			<span style="display: inline-block;margin: 0 15px;color: #D9D9D9;">|</span>
			<span>评价明细</span>
		</div>

		<div style="margin:2% 0;display: inline-block;">
			<div style="position: relative;display: inline-block;margin: 10px 0px;">
				<span>筛选类型：</span>
				<el-select v-model="grade" style="width:150px;margin-left: 10px;" @change="animeDat2(grade)">
					<el-option v-for="item in scoreTypes" :key="item.value" :label="item.label" :value="item.value">
					</el-option>
				</el-select>&nbsp;&nbsp;&nbsp;
			</div>
			<el-button style="margin-left:15px;" size="mini" type="primary" icon="document" @click="dataSelect">查询
			</el-button>
			<el-button style="margin-left:15px;" size="mini" type="primary" icon="document" @click="cleans2">重置
			</el-button>
		</div>
		<el-table v-loading="tableDataLoading" :data="tableData.list">
			<el-table-column fixed prop="evaluateId" label="编号" width="80">
			</el-table-column>
			<!-- <el-table-column prop = "nickName" label = "用户昵称" width = "120">
      	<template slot-scope="scope">
      		<div style="color: #4f9dec;cursor: pointer;" @click="updates(scope.row)">{{scope.row.nickName?scope.row.nickName:'未绑定'}}</div>
      	</template>
      </el-table-column> -->
			<el-table-column prop="userAvatar" label="用户头像" width="100">
				<template slot-scope="scope">
					<div style="display: inline-block; margin: 3px;">
						<el-popover placement="top-start" title="" trigger="hover">
							<img style="width: 50px; height: 50px" :src="scope.row.userAvatar" alt="" slot="reference">
							<img style="width: 300px; height: auto" :src="scope.row.userAvatar" alt="">
						</el-popover>
					</div>

				</template>
			</el-table-column>

			<el-table-column prop="userName" label="用户" width="150">
				<template slot-scope="scope">
					<span style="color: #4f9dec;cursor: pointer;">{{scope.row.userName ? scope.row.userName : '暂无'}}</span>
				</template>
			</el-table-column>

			<el-table-column prop="indentNumber" label="订单号">
			</el-table-column>

			<el-table-column prop="satisfactionFlag" label="评分">
			</el-table-column>
			<el-table-column prop="evaluateImg" label="评论图片" width="280">
				<template slot-scope="scope">
					<div v-if="scope.row.evaluateImg">
						<el-popover placement="top-start" title="" trigger="hover">
							<img style="width: 50px; height: 50px;margin: 3px;" :src="scope.row.evaluateImg" alt="" slot="reference">
							<img style="width: 200px; height: 200px" :src="scope.row.evaluateImg" alt="">
						</el-popover>
					</div>
				</template>
			</el-table-column>
			<el-table-column prop="evaluateMessage" label="评价内容">
			</el-table-column>
			<el-table-column prop="shopReplyMessage" label="商家回复">
			</el-table-column>
			<el-table-column prop="createTime" label="时间" width="150">
			</el-table-column>
			<el-table-column prop="createTime" label="操作" width="150">
				<template slot-scope="scope">
					<el-button style="margin-left:15px;" size="mini" type="primary" icon="document"
						@click="huifu(scope.row)" v-if="scope.row.shopReplyMessage==''||scope.row.shopReplyMessage==null">回复
					</el-button>
				</template>
			</el-table-column>
		</el-table>
		<div style="text-align: center;margin-top: 10px;">
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:page-sizes="[10, 20, 30, 40,100]" :page-size="limit" :current-page="page"
				layout="total,sizes, prev, pager, next" :total="tableData.totalCount">
			</el-pagination>
		</div>

		<!--    回复评价-->
		<el-dialog title="回复" :visible.sync="dialogVisible" width="50%">
			<div style="margin-bottom: 10px;">
			  <span style="width: 200px;display: inline-block;text-align: right;">回复：</span>
			  <el-input style="width:50%;" v-model="shopReplyMessage" type="textarea" placeholder="请输入回复"></el-input>
			</div>
			<div slot="footer" class="dialog-footer">
			  <el-button @click="dialogVisible = false">取 消</el-button>
			  <el-button type="primary" @click="refuseto()">确 定</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				limit: 10,
				page: 1,
				activeName: 'first',
				tableDataLoading: false,
				grade: '',
				dialogFormVisible: false,
				tableData: {},
				scoreTypes: [{ //后台定义 1 2差评 3 4中评 5是好评
						label: '全部',
						value: ''
					},
					{
						label: '好评',
						value: 1
					},
					{
						label: '中评',
						value: 2
					},
					{
						label: '差评',
						value: 3
					},
				],
				shopId: '',
				dialogVisible: false,
				orderNumber:'',
				shopReplyMessage:'',
			}
		},
		methods: {
			//提交查询
			animeDat2(state) {
				this.page = 1
				this.grade = state;
				this.dataSelect()
			},
			cleans2() {
				this.page = 1
				this.grade = '';
				this.dataSelect()
			},
			//查看用户详情
			goUserInfo(userId) {
				this.$router.push({
					path: '/userDetail',
					query: {
						userId
					}
				})

			},
			handleSizeChange(val) {
				this.limit = val;
				this.dataSelect()
			},
			handleCurrentChange(val) {
				this.page = val;
				this.dataSelect()
			},
			// 获取派单数据列表
			dataSelect() {
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('admin/shop/selectEvaluateByShopId'),
					method: 'get',
					params: this.$http.adornParams({
						'page': this.page,
						'limit': this.limit,
						'shopId': this.shopId,
						'grade': this.grade,
					})
				}).then(({
					data
				}) => {
					this.tableDataLoading = false
					let returnData = data.data.pageUtils;

					for (var i = 0; i < returnData.list.length; i++) {
						if (returnData.list[0].image) {
							returnData.list[0].newImage = returnData.list[0].image.split(',')
						}
					}
					this.tableData = returnData
				})
			},
			// 返回上一级
			prev() {
				this.$router.back()
			},
			huifu(row) {		
				this.shopReplyMessage = ''
				this.orderNumber = row.indentNumber
				this.dialogVisible = true
			},
			refuseto(){
				if (this.shopReplyMessage == '') {
				  this.$notify({
				    title: '提示',
				    duration: 1800,
				    message: '请输入回复内容',
				    type: 'warning'
				  })
				  return
				}
				this.$http({
					url: this.$http.adornUrl('orders/shopReplyEvaluate'),
					method: 'post',
					params: this.$http.adornParams({
						'shopReplyMessage': this.shopReplyMessage,
						'orderNumber': this.orderNumber
					})
				}).then(({
					data
				}) => {
					if(data.code==0){
						this.$message({
						  message: '操作成功',
						  type: 'success',
						  duration: 1500,
						  onClose: () => {
							  this.dataSelect()
							  this.dialogVisible = false
						  }
						})
					}else{
						this.$message({
						  message: data.msg,
						  type: 'warning',
						  duration: 1500,
						  onClose: () => {}
						})
					}
				})
			},
		},
		mounted() {
			
			this.shopId = this.$route.query.shopId
			this.dataSelect()
		}
	};
</script>

<style>

</style>
